import { Injectable } from '@angular/core';
import { HttpResponse } from '@angular/common/http';
import { Resolve, ActivatedRouteSnapshot, RouterStateSnapshot, Routes } from '@angular/router';
import { UserRouteAccessService } from 'app/core';
import { of } from 'rxjs';
import { map } from 'rxjs/operators';
import { Stewarder } from 'app/shared/model/stewarder.model';
import { StewarderService } from './stewarder.service';
import { StewarderComponent } from './stewarder.component';
import { StewarderDetailComponent } from './stewarder-detail.component';
import { StewarderUpdateComponent } from './stewarder-update.component';
import { StewarderDeletePopupComponent } from './stewarder-delete-dialog.component';
import { IStewarder } from 'app/shared/model/stewarder.model';

@Injectable({ providedIn: 'root' })
export class StewarderResolve implements Resolve<IStewarder> {
    constructor(private service: StewarderService) {}

    resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
        const id = route.params['id'] ? route.params['id'] : null;
        if (id) {
            return this.service.find(id).pipe(map((stewarder: HttpResponse<Stewarder>) => stewarder.body));
        }
        return of(new Stewarder());
    }
}

export const stewarderRoute: Routes = [
    {
        path: 'stewarder',
        component: StewarderComponent,
        data: {
            authorities: ['ROLE_USER'],
            pageTitle: 'sharedelectricbicycleApp.stewarder.home.title'
        },
        canActivate: [UserRouteAccessService]
    },
    {
        path: 'stewarder/:id/view',
        component: StewarderDetailComponent,
        resolve: {
            stewarder: StewarderResolve
        },
        data: {
            authorities: ['ROLE_USER'],
            pageTitle: 'sharedelectricbicycleApp.stewarder.home.title'
        },
        canActivate: [UserRouteAccessService]
    },
    {
        path: 'stewarder/new',
        component: StewarderUpdateComponent,
        resolve: {
            stewarder: StewarderResolve
        },
        data: {
            authorities: ['ROLE_USER'],
            pageTitle: 'sharedelectricbicycleApp.stewarder.home.title'
        },
        canActivate: [UserRouteAccessService]
    },
    {
        path: 'stewarder/:id/edit',
        component: StewarderUpdateComponent,
        resolve: {
            stewarder: StewarderResolve
        },
        data: {
            authorities: ['ROLE_USER'],
            pageTitle: 'sharedelectricbicycleApp.stewarder.home.title'
        },
        canActivate: [UserRouteAccessService]
    }
];

export const stewarderPopupRoute: Routes = [
    {
        path: 'stewarder/:id/delete',
        component: StewarderDeletePopupComponent,
        resolve: {
            stewarder: StewarderResolve
        },
        data: {
            authorities: ['ROLE_USER'],
            pageTitle: 'sharedelectricbicycleApp.stewarder.home.title'
        },
        canActivate: [UserRouteAccessService],
        outlet: 'popup'
    }
];
